package com.stockz.equity.charting.painter;

import java.awt.Graphics2D;
import java.awt.Rectangle;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.stockz.equity.charting.painter.axis.PriceAxisPainter;
import com.stockz.equity.charting.painter.axis.TimeAxisPainter;
import com.stockz.equity.charting.view.StockChart;
import com.stockz.equity.pattern.Painter;

@Component
public class GridPainter implements Painter<StockChart> {

	@Autowired private TimeAxisPainter timeAxisPainter;
	@Autowired private PriceAxisPainter priceAxisPainter;
	
	@Override
	public void paint(Graphics2D g,StockChart view, Rectangle r) {
		int[] values = null;
		g.setColor(view.getStockChartPanel().getStockChartPanelSkin().getGridColor());
		if(timeAxisPainter != null 
				&& timeAxisPainter.getCurrentXmarks() != null 
				&& timeAxisPainter.getCurrentXmarks().length != 0){
			values = timeAxisPainter.getCurrentXmarks();
			for(int x : values){
				g.drawLine(x, r.y, x, r.y + r.height);
			}
		}
		if(priceAxisPainter != null 
				&& priceAxisPainter.getCurrentYmarks() != null 
				&& priceAxisPainter.getCurrentYmarks().length != 0){
			values = priceAxisPainter.getCurrentYmarks();
			for(int y : values){
				g.drawLine(r.x, y, r.x +r.width, y);
			}
		}

	}
}
